package cn.ticket.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ticket.model.Constants;
import cn.ticket.model.Staff;
import cn.ticket.model.Workbuses;
import cn.ticket.model.Workrefundlog;
import cn.ticket.model.Workseatreason;
import cn.ticket.model.Workticketorder;
import cn.ticket.service.RefundLogService;
import cn.ticket.service.StaffService;
import cn.ticket.service.Utility;
import cn.ticket.service.WorkBusesService;
import cn.ticket.service.WorkRefundLogService;
import cn.ticket.service.WorkSeatReasonService;
import cn.ticket.service.WorkTicketOrderService;

@Controller
@RequestMapping("workTicketOrder")
public class WorkTicketOrderController {

	@Autowired
	private StaffService staffService;
	@Autowired
	private WorkBusesService workBusesService;
	@Autowired
	private WorkTicketOrderService workTicketService;
	
	@Autowired
	WorkRefundLogService workRefundLogService;
	@Autowired
	WorkSeatReasonService workSeatReasonService;

	// 手机工作车订票
	@RequestMapping(value = "insert", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	@ResponseBody
	public String insert(@RequestBody Map<String, String> args) {

		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String seatNumber = args.get("seatNumber");
		String seatName = args.get("seatName");
		int workBusId = Integer.parseInt(args.get("busId"));
		int staffId = Integer.parseInt(args.get("staffId"));
		String seatContent = args.get("seatContent");
		int seatreasonid = Integer.parseInt(args.get("reasonId"));

		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != staffId) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败");
			return Utility.gson.toJson(result);
		}
		if (staff.getIseabled() == false) {
			result.put("status", 1002);
			result.put("message", "用户订票权限已被冻结,请联系科室主任或管理员");
			return Utility.gson.toJson(result);
		}
		if (staff.getStatus().equals("4")) {
			result.put("status", 1002);
			result.put("message", "暂无上下班班车权限");
			return Utility.gson.toJson(result);
		}
		Workbuses workBuses = workBusesService.selectByPrimaryKey(workBusId);
		if (!workBuses.getIsneedaudit()) {
			seatreasonid=10;
			if (seatContent==null) {
				seatContent="上下班自动通过";
			}
			
		}
		Date departureDate = workBuses.getDeparturedate();
//		if ((new Date()).getTime() > (departureDate.getTime() - 1000 * 60 * Constants.workTicketStopMins)) {
//			result.put("status", 1002);
//			result.put("message", "已过订票时间");
//			return Utility.gson.toJson(result);
//		}
		if ((new Date()).getTime() < workBuses.getValiditydate().getTime()||(new Date()).getTime()>workBuses.getEndbusdate().getTime()) {
			result.put("status", 1002);
			result.put("message", "此车订票时段为"+new SimpleDateFormat(Constants.DATEFORMAT).format(workBuses.getValiditydate())+" 至 "+new SimpleDateFormat(Constants.DATEFORMAT).format(workBuses.getEndbusdate()));
			return Utility.gson.toJson(result);
		}
		synchronized (this) {
			Workticketorder workticketorder = new Workticketorder();
			workticketorder.setSeatname(seatName);		
			workticketorder.setSeatcontent(seatContent);			
			workticketorder.setSeatnumber((byte) Integer.parseInt(seatNumber));
			workticketorder.setSeatreasonid((byte) seatreasonid);
			workticketorder.setWorkbusesid(workBusId);
			workticketorder.setStaffid(staffId);
			workticketorder.setAuditstatus((byte) 0);
			if (!workBuses.getIsneedaudit()) {
				if (staff.getName().equals(seatName)) {
					workticketorder.setAuditstatus((byte) 1);
					workticketorder.setAuditstaffid(3180);
				}
				else {
					workticketorder.setAuditstatus((byte) 2);
				}
			}
			int num=0;
			try {
				 num = workTicketService.insertSelective(workticketorder);
			} catch (Exception e) {
				// TODO: handle exception
				result.put("status", 1002);
				result.put("message", "订票失败!");
				return Utility.gson.toJson(result);
			}
			
			if (num == 1) {
				if (!workBuses.getIsneedaudit()) {		
					workBusesService.seatOccupationAuditedAdd1(workBuses.getId());
					result.put("message", "订座成功! 座号:" + seatNumber + " 乘坐人:" + seatName);
				}else {
					workBuses.setAuditingcount((short) (workBuses.getAuditingcount() + 1));					
					result.put("message", "申请成功,请等待审批! 座号:" + seatNumber + " 乘坐人:" + seatName);
					workBusesService.updateByPrimaryKeySelective(workBuses);
				}
				
				workBuses.setOccupation((short) (workBuses.getOccupation() + 1));
				staff.setWorkticketcount(staff.getWorkticketcount() + 1);				
				staffService.updateByPrimaryKey(staff);
				//生成第二辆车
				if (workBuses.getOccupation().shortValue()==workBuses.getSeatscount().shortValue()&&workBuses.getIsneedaudit()==false) {
					List<Workbuses> workbuses2=workBusesService.getByDepartureDate(workBuses.getDeparturedate());
					if (workbuses2.size()<2) {
						Workbuses workbusesGenerate = new Workbuses();
						workbusesGenerate.setRouteid(workBuses.getRouteid());
						workbusesGenerate.setSeatscount(workBuses.getSeatscount());
						workbusesGenerate.setIsneedaudit(false);
						workbusesGenerate.setDeparturedate1(workBuses.getDeparturedate());
						workbusesGenerate.setEndbusdate1(workBuses.getEndbusdate());
						workbusesGenerate.setValiditydate1(workBuses.getValiditydate());						
						workBusesService.insert(workbusesGenerate);
					}					
				}
				
				result.put("status", 1001);				
				return Utility.gson.toJson(result);
			} else {
				result.put("status", 1002);
				result.put("message", "订票失败!");
				return Utility.gson.toJson(result);
			}
		}
	}

	/*
	 * 车队订票接口
	 */
	@RequestMapping(value = "adminInsert", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	@ResponseBody
	public String adminInsert(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String seatNumber = args.get("seatNumber");
		String seatName = args.get("seatName");
		int workBusId = Integer.parseInt(args.get("busId"));
		Integer staffId = Integer.parseInt(args.get("staffId"));
		String seatContent = "后台直接订票";
		int seatreasonid = 1;
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != staffId.intValue()) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败");
			return Utility.gson.toJson(result);
		}
		if (staff.getIseabled() == false) {
			result.put("status", 1002);
			result.put("message", "用户订票权限已被冻结,请联系科室主任或管理员");
			return Utility.gson.toJson(result);
		}

		Workbuses workBuses = workBusesService.selectByPrimaryKey(workBusId);
		Date departureDate = workBuses.getDeparturedate();
		if ((new Date()).getTime() > (departureDate.getTime() - 1000 * 60 * Constants.workTicketStopMins)) {
			result.put("status", 1002);
			result.put("message", "已过订票时间");
			return Utility.gson.toJson(result);
		}

		Workticketorder workticketorder = new Workticketorder();
		workticketorder.setSeatname(seatName);
		workticketorder.setSeatcontent(seatContent);
		workticketorder.setSeatnumber((byte) Integer.parseInt(seatNumber));
		workticketorder.setSeatreasonid((byte) seatreasonid);
		workticketorder.setWorkbusesid(workBusId);
		workticketorder.setStaffid(staffId);
		
		workticketorder.setAuditstatus((byte) 3);

		int num = workTicketService.insertSelective(workticketorder);
		if (num == 1) {
		//	workBuses.setAuditingcount((short) (workBuses.getAuditingcount() + 1));
			workBuses.setAuditedcount((short) (workBuses.getAuditedcount()+1));
			workBuses.setOccupation((short) (workBuses.getOccupation() + 1));
			workBusesService.updateByPrimaryKeySelective(workBuses);
			result.put("status", 1001);
			result.put("message", "订票成功! 座位号:" + seatNumber + " 乘坐人:" + seatName);
			return Utility.gson.toJson(result);
		} else {
			result.put("status", 1002);
			result.put("message", "订票失败!");
			return Utility.gson.toJson(result);
		}
	}

	/*
	 * 手机退票接口
	 */
	@RequestMapping(value = "delete", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	@ResponseBody
	public String delete(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		// int seatNumber = Integer.parseInt(args.get("seatNumber"));
		String seatName = args.get("seatName");
		int ticketId = Integer.parseInt(args.get("ticketId"));
		Workticketorder workticketorder = workTicketService.selectByPrimaryKey(ticketId);
		int staffId = Integer.parseInt(args.get("staffId"));
		int workBusId = workticketorder.getWorkbusesid();
		String cancelReason = args.get("cancelReason");
		if (cancelReason == null) {
			cancelReason = "";
		}
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != staffId) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败");
			return Utility.gson.toJson(result);
		}
		if (staff.getIseabled() == false) {
			result.put("status", 1002);
			result.put("message", "用户订票权限已被冻结,请联系科室主任或管理员");
			return Utility.gson.toJson(result);
		}
		Workbuses workBuses = workBusesService.selectByPrimaryKey(workBusId);
		// Workticketorder workticketorder =
		// workTicketService.selectByPrimaryKey(ticketId);
		if (workBuses.getDeparturedate().getTime() < new Date().getTime() + 1000 * 60 * Constants.workRefundStopMins) {
			result.put("status", 1002);
			result.put("message", "开车前" + Constants.workRefundStopMins + "分钟不许退票,请珍惜所内资源,慎重订票!!");
			return Utility.gson.toJson(result);
		}
		synchronized (this) {
			int num = workTicketService.deleteByPrimaryKey(ticketId);
			if (num == 1) {

				workBuses.setOccupation((short) (workBuses.getOccupation() - 1));
				if (workticketorder.getAuditstatus() == 0) {
					workBuses.setAuditingcount((short) (workBuses.getAuditingcount() - 1));
					workBusesService.updateByPrimaryKeySelective(workBuses);
				} else {
					workBusesService.seatOccupationAuditedRemove1(workBuses.getId());
				}
				staff.setWorkticketcount(staff.getWorkticketcount() - 1);				
				staffService.updateByPrimaryKeySelective(staff);
				Workrefundlog refundlog = new Workrefundlog();
				refundlog.setBusesid(workBuses.getId());
				refundlog.setStaffid(staff.getId());
				refundlog.setSeatname(seatName);
				refundlog.setSeatnumber(workticketorder.getSeatnumber());
				refundlog.setReason(cancelReason);
				workRefundLogService.insertSelective(refundlog);

				result.put("status", 1001);
				result.put("message", "退票成功");
				return Utility.gson.toJson(result);
			} else {
				result.put("status", 1002);
				result.put("message", "退票失败!");
				return Utility.gson.toJson(result);
			}

		}
	}

	/*
	 * 车队退票接口
	 */
	@RequestMapping(value = "adminDelete", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	@ResponseBody
	public String adminDelete(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String seatName = args.get("seatName");
		int ticketId = Integer.parseInt(args.get("ticketId"));
		Workticketorder workticketorder = workTicketService.selectByPrimaryKey(ticketId);
		int staffId = Integer.parseInt(args.get("staffId"));
		int workBusId = workticketorder.getWorkbusesid();
		String cancelReason = args.get("cancelReason");
		if (cancelReason == null) {
			cancelReason = "";
		}
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != staffId) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败");
			return Utility.gson.toJson(result);
		}
		if (staff.getIseabled() == false) {
			result.put("status", 1002);
			result.put("message", "用户订票权限已被冻结,请联系科室主任或管理员");
			return Utility.gson.toJson(result);
		}
		Workbuses workBuses = workBusesService.selectByPrimaryKey(workBusId);
	//	Workticketorder workticketorder = workTicketService.selectByPrimaryKey(ticketId);
		if (workBuses.getDeparturedate().getTime() < new Date().getTime() + 1000 * 60 * Constants.workRefundStopMins) {
			result.put("status", 1002);
			result.put("message", "开车前" + Constants.workRefundStopMins + "分钟不许退票,请珍惜所内资源,慎重订票!!");
			return Utility.gson.toJson(result);
		}

		int num = workTicketService.deleteByPrimaryKey(ticketId);
		if (num == 1) {

			workBuses.setOccupation((short) (workBuses.getOccupation() - 1));
			
			
			workBuses.setAuditedcount((short) (workBuses.getAuditedcount() - 1));
		

			workBusesService.updateByPrimaryKeySelective(workBuses);

			Workrefundlog refundlog = new Workrefundlog();
			refundlog.setBusesid(workBuses.getId());
			refundlog.setStaffid(staff.getId());
			refundlog.setSeatname(seatName);
			refundlog.setSeatnumber(workticketorder.getSeatnumber());
			refundlog.setReason(cancelReason);
			workRefundLogService.insertSelective(refundlog);

			result.put("status", 1001);
			result.put("message", "退票成功");
			return Utility.gson.toJson(result);
		} else {
			result.put("status", 1002);
			result.put("message", "退票失败!");
			return Utility.gson.toJson(result);
		}
	}

	/*
	 * 根据车次车辆的id 获取座位的乘坐情况
	 */
	@RequestMapping(value = "getInfoByBusId", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getInfoByBusId(@RequestBody Map<String, Integer> args) {
		Map<String, Object> result = new HashMap<>();
		Integer busId = args.get("busId");
		List<Map<String, Object>> ticketInfos = workTicketService.getInfoByBusId(busId);
		if (ticketInfos.isEmpty()) {
			result.put("status", 1002);
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", ticketInfos);
		return Utility.gson.toJson(result);
	}

	/*
	 * 获取申请原因的类别
	 */
	@RequestMapping(value = "getWorkSeatReason", method = RequestMethod.GET, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getWorkSeatReason() {
		List<Workseatreason> workseatreasons = workSeatReasonService.getAll();
		return Utility.createJsonMsg(1001, "ok", workseatreasons);
	}

	/*
	 * 科室主任获取申请坐车数据
	 */
	@RequestMapping(value = "getAuditingTicketInfoByAuditor", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getAuditingTicketInfoByAuditor(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String staffId = args.get("staffId");
		// int workTicketId=Integer.parseInt(args.get("workTicketId"));

		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != Integer.parseInt(staffId)) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败!");
			return Utility.gson.toJson(result);
		}
		if (staff.getLevel() == 1) {
			result.put("status", 1002);
			result.put("message", "无权限!");
			return Utility.gson.toJson(result);
		}
		List<Map<String, Object>> workticketorders = workTicketService
				.getAuditingTicketInfoByDepartmentId(staff.getDepartmentid());
		if (workticketorders.isEmpty()) {
			result.put("status", 1002);
			result.put("message", "无职工乘坐申请!");
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", workticketorders);
		return Utility.gson.toJson(result);
	}

	/*
	 * 科室主任获取已审批的坐车数据
	 */
	@RequestMapping(value = "getAuditedTicketInfoByAuditor", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getAuditedTicketInfoByAuditor(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String staffId = args.get("staffId");
		// int workTicketId=Integer.parseInt(args.get("workTicketId"));

		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != Integer.parseInt(staffId)) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败!");
			return Utility.gson.toJson(result);
		}
		if (staff.getLevel() == 1) {
			result.put("status", 1002);
			result.put("message", "无权限!");
			return Utility.gson.toJson(result);
		}
		List<Map<String, Object>> workticketorders = workTicketService
				.getAuditedTicketInfoByStaffId(Integer.parseInt(staffId));
		if (workticketorders.isEmpty()) {
			result.put("status", 1002);
			result.put("message", "无职工乘坐申请!");
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", workticketorders);
		return Utility.gson.toJson(result);
	}

	/**
	 * 科室主任审批请求
	 **/
	@RequestMapping(value = "auditTicketInfoByAuditor", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String auditTicketInfoByAuditor(@RequestBody Map<String, String> args, HttpServletRequest request) {
		String client_ip = "";
		if (request.getHeader("x-forwarded-for") == null) {
			client_ip = request.getRemoteAddr();
		} else {
			client_ip = request.getHeader("x-forwarded-for");
		}
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String staffId = args.get("staffId");
		int workTicketId = Integer.parseInt(args.get("workTicketId"));
		String auditreason = args.get("auditreason");
		if (auditreason == null) {
			auditreason = "";
		}
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != Integer.parseInt(staffId)) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败!");
			return Utility.gson.toJson(result);
		}
		if (staff.getPassword().equals("666666")) {
			result.put("status", 1002);
			result.put("message", "默认密码无审核权限,请修改密码!");
			return Utility.gson.toJson(result);
		}
		if (staff.getLevel() == 1) {
			result.put("status", 1002);
			result.put("message", "无权限!");
			return Utility.gson.toJson(result);
		}
		Workticketorder workticketorder = workTicketService.selectByPrimaryKey(workTicketId);
		if (workticketorder == null) {
			result.put("status", 1002);
			result.put("message", "无乘坐信息,请刷新检查!");
			return Utility.gson.toJson(result);
		}
		Workbuses workbuses = workBusesService.selectByPrimaryKey(workticketorder.getWorkbusesid());
		if (auditreason.equals("delete%%%Directly000233331111")) {// 拒绝的代码号
			if (workTicketService.deleteByPrimaryKey(workTicketId) == 1) {
				workbuses.setAuditingcount((short) (workbuses.getAuditingcount() - 1));
				workbuses.setOccupation((short) (workbuses.getOccupation() - 1));
				workBusesService.updateByPrimaryKeySelective(workbuses);
				result.put("status", 1001);
				return Utility.gson.toJson(result);
			}
		}
		String[] ip = client_ip.split(",");
		workticketorder.setAuditstaffip(client_ip);
		if (ip.length == 2) {
			workticketorder.setAuditstaffip(ip[1]);
		}

		workticketorder.setAuditreason(auditreason);
		// workticketorder.setAuditstatus((byte) 1);
		if (workTicketService.AuditTicket(workticketorder, staff)) {
			workbuses.setAuditedcount((short) (workbuses.getAuditedcount() + 1));
			workbuses.setAuditingcount((short) (workbuses.getAuditingcount() - 1));
			workBusesService.updateByPrimaryKeySelective(workbuses);
			result.put("status", 1001);
			return Utility.gson.toJson(result);
		}
		result.put("status", 1002);
		result.put("message", "审核失败!");
		return Utility.gson.toJson(result);
	}

	/*
	 * 车队获取申请坐车数据
	 */
	@RequestMapping(value = "getAuditingTicketInfoByAdmin", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getAuditingTicketInfoByAdmin(@RequestBody Map<String, String> args) {
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String staffId = args.get("staffId");
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != Integer.parseInt(staffId)) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败!");
			return Utility.gson.toJson(result);
		}
		if (staff.getId() != 3000) {
			result.put("status", 1002);
			result.put("message", "无权限!");
			return Utility.gson.toJson(result);
		}
		List<Map<String, Object>> workticketorders = workTicketService.getAuditingTicketInfo();
		if (workticketorders.isEmpty()) {
			result.put("status", 1002);
			result.put("message", "无职工乘坐申请!");
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", workticketorders);
		return Utility.gson.toJson(result);
	}

	/**
	 * 车队审批请求
	 **/
	@RequestMapping(value = "auditTicketInfoByAdmin", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String auditTicketInfoByAdmin(@RequestBody Map<String, String> args, HttpServletRequest request) {
		String client_ip = "";
		if (request.getHeader("x-forwarded-for") == null) {
			client_ip = request.getRemoteAddr();
		} else {
			client_ip = request.getHeader("x-forwarded-for");
		}
		Map<String, Object> result = new HashMap<>();
		String phone = args.get("phone");
		String password = args.get("password");
		String staffId = args.get("staffId");
		int workTicketId = Integer.parseInt(args.get("workTicketId"));
		String auditreason = args.get("auditreason");
		if (auditreason == null) {
			auditreason = "";
		}
		Staff staff = staffService.validateStaff(phone, password);
		if (staff == null || staff.getId() != Integer.parseInt(staffId)) {
			result.put("status", 1002);
			result.put("message", "登录账户验证失败!");
			return Utility.gson.toJson(result);
		}
		if (staff.getId() != 3000) {
			result.put("status", 1002);
			result.put("message", "无权限!");
			return Utility.gson.toJson(result);
		}
		Workticketorder workticketorder = workTicketService.selectByPrimaryKey(workTicketId);
		if (workticketorder == null) {
			result.put("status", 1002);
			result.put("message", "无乘坐信息,请刷新检查!");
			return Utility.gson.toJson(result);
		}
		workticketorder.setAuditstaffip(client_ip);
		workticketorder.setAuditreason(auditreason);
		if (workTicketService.AuditTicket(workticketorder, staff)) {
			result.put("status", 1001);
			return Utility.gson.toJson(result);
		}
		result.put("status", 1002);
		result.put("message", "审核失败!");
		return Utility.gson.toJson(result);
	}

	/*
	 * 根据员工号获取未使用车票
	 */
	@RequestMapping(value = "getValidateTicketsInfoByStaffId", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getValidateTicketsInfoByStaffId(@RequestBody Map<String, Integer> args) {
		Map<String, Object> result = new HashMap<>();
		Integer staffId = args.get("staffId");
		List<Map<String, Object>> ticketInfos = workTicketService.getValidateTicketInfoByStaffId(staffId);
		if (ticketInfos.isEmpty()) {
			result.put("status", 1002);
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", ticketInfos);
		return Utility.gson.toJson(result);
	}

	/*
	 * 根据员工号获取已使用车票
	 */
	@RequestMapping(value = "getInvalidateTicketsInfoByStaffId", method = RequestMethod.POST, produces = {
			"application/json;charset=utf-8" })
	@ResponseBody
	public String getInvalidateTicketsInfoByStaffId(@RequestBody Map<String, Integer> args) {
		Map<String, Object> result = new HashMap<>();
		Integer staffId = args.get("staffId");
		List<Map<String, Object>> ticketInfos = workTicketService.getInvalidateTicketInfoByStaffId(staffId);
		if (ticketInfos.isEmpty()) {
			result.put("status", 1002);
			return Utility.gson.toJson(result);
		}
		result.put("status", 1001);
		result.put("body", ticketInfos);
		return Utility.gson.toJson(result);
	}
}
